package org.acsis.jee.dao.hibernate;

import java.util.Date;
import java.util.List;

import org.acsis.jee.dao.TrajetDAO;
import org.acsis.jee.pojo.Trajet;
import org.hibernate.Query;

public class TrajetDAOHibernate extends BasicHibernateDAO<Trajet, Integer> implements TrajetDAO{

	@SuppressWarnings("unchecked")
	@Override
	public List<Trajet> retreiveTrajetByDateAndLieuDepart(Date dateDepart,
			int lieuDepart) {
		
		if(session != null){
			
			if(dateDepart != null){
				session.enableFilter("dateDepartFilter").setParameter("asOFDateDepart", dateDepart);
			}
			
			if(lieuDepart > 0){
				session.enableFilter("lieuFilter").setParameter("asOFLieuDepart", lieuDepart);
			}
			
			Query q = session.createQuery("from Trajet");
			
			return q.list();
		}
		
		return null;
	}

	@Override
	public void deleteAll() {
		session.createQuery("delete Trajet").executeUpdate();
	}

}
